package com.mcx.modules.proto;

import com.mcx.modules.common.IProto;
import com.mcx.modules.common.MMO_DataStream;

import java.io.*;
import java.util.*;

/**
 * 服务器返回当前选择的阵容信息
 */
public class RoleOperation_SelectLineupInfoReturnProto implements IProto
{
    private static MMO_DataStream dataStream = new MMO_DataStream();

    @Override
    public short getProtoCode() { return 10011; }

    public Integer Id; //阵容Id
    public String Name; //阵容名称
    public Integer PlayerId; //玩家Id
    public String RoleIds; //角色Ids
    public Integer RoleCount; //角色数量
    public ArrayList<RoleItem> RoleList; //角色项

    /**
     * 角色项
     */
    public static class RoleItem
    {
        public Integer Id; //角色Id
        public Integer Status; //角色状态
        public Integer PlayerId; //角色所属玩家Id
        public Integer RoleId; //角色所属Id
        public String Name; //角色名称
        public Integer Sex; //角色性别
        public Integer Level; //角色等级
        public Integer Exp; //角色经验
        public Integer MaxHP; //最大HP
        public Integer MaxMP; //最大MP
        public Integer CurrHP; //当前HP
        public Integer CurrMP; //当前MP
        public Integer Attack; //攻击力
        public Integer Defense; //防御力
        public String Cri; //暴击率
        public String VioInjury; //暴击伤害
        public Integer Res; //抗性
    }

    public byte[] ToArray() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (DataOutputStream outputStream = new DataOutputStream(out)) {
            dataStream.outputStream = outputStream;
            dataStream.WriteShort(getProtoCode());
            dataStream.WriteInt(Id);
            dataStream.WriteUTF8String(Name);
            dataStream.WriteInt(PlayerId);
            dataStream.WriteUTF8String(RoleIds);
            dataStream.WriteInt(RoleCount);
            for (int i = 0; i < RoleCount; i++) {
                dataStream.WriteInt(RoleList.get(i).Id);
                dataStream.WriteInt(RoleList.get(i).Status);
                dataStream.WriteInt(RoleList.get(i).PlayerId);
                dataStream.WriteInt(RoleList.get(i).RoleId);
                dataStream.WriteUTF8String(RoleList.get(i).Name);
                dataStream.WriteInt(RoleList.get(i).Sex);
                dataStream.WriteInt(RoleList.get(i).Level);
                dataStream.WriteInt(RoleList.get(i).Exp);
                dataStream.WriteInt(RoleList.get(i).MaxHP);
                dataStream.WriteInt(RoleList.get(i).MaxMP);
                dataStream.WriteInt(RoleList.get(i).CurrHP);
                dataStream.WriteInt(RoleList.get(i).CurrMP);
                dataStream.WriteInt(RoleList.get(i).Attack);
                dataStream.WriteInt(RoleList.get(i).Defense);
                dataStream.WriteUTF8String(RoleList.get(i).Cri);
                dataStream.WriteUTF8String(RoleList.get(i).VioInjury);
                dataStream.WriteInt(RoleList.get(i).Res);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out.toByteArray();    }
    public static RoleOperation_SelectLineupInfoReturnProto GetProto(byte[] buffer) {
        RoleOperation_SelectLineupInfoReturnProto proto = new RoleOperation_SelectLineupInfoReturnProto();
        try (DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(buffer))) {
            dataStream.inputStream = inputStream;
            proto.Id = dataStream.ReadInt();
            proto.Name = dataStream.ReadUTF8String();
            proto.PlayerId = dataStream.ReadInt();
            proto.RoleIds = dataStream.ReadUTF8String();
            proto.RoleCount = dataStream.ReadInt();
            proto.RoleList = new ArrayList<RoleItem>();
            for (int i = 0; i < proto.RoleCount; i++) {
                RoleItem _Role = new RoleItem();
                _Role.Id = dataStream.ReadInt();
                _Role.Status = dataStream.ReadInt();
                _Role.PlayerId = dataStream.ReadInt();
                _Role.RoleId = dataStream.ReadInt();
                _Role.Name = dataStream.ReadUTF8String();
                _Role.Sex = dataStream.ReadInt();
                _Role.Level = dataStream.ReadInt();
                _Role.Exp = dataStream.ReadInt();
                _Role.MaxHP = dataStream.ReadInt();
                _Role.MaxMP = dataStream.ReadInt();
                _Role.CurrHP = dataStream.ReadInt();
                _Role.CurrMP = dataStream.ReadInt();
                _Role.Attack = dataStream.ReadInt();
                _Role.Defense = dataStream.ReadInt();
                _Role.Cri = dataStream.ReadUTF8String();
                _Role.VioInjury = dataStream.ReadUTF8String();
                _Role.Res = dataStream.ReadInt();
                proto.RoleList.add(_Role);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return proto;
    }
}